added some development tools
[windows-sources.git] / developer / Samples / NET 4.6 / swarm / Swarm Logic / Number Generators / UniformRandom.cs
blobd26e3dc44969cc95c509b2e7ed0627f9a07655c7
1 using System;
3 namespace Swarm_Logic
5 /// <summary>
6 /// This class implements a uniform random generator with a minimum and maximum values.
7 /// </summary>
8 public class UniformRandom : NumberGenerator
10 // Represents the minimum value reteurned by this uniform random generator.
11 private double Min;
13 // Represents the maximum value reteurned by this uniform random generator.
14 private double Max;
16 // Represents the pseudo-random number generator used to generate random numbers.
17 private Random MyUniformRandom;
19 /// <summary>
20 /// Creates a new uniform random generator with the specified minimum and maximum values.
21 /// </summary>
22 /// <param name="Min">Represents the minimum value reteurned by this uniform random generator.</param>
23 /// <param name="Max">Represents the maximum value reteurned by this uniform random generator.</param>
24 public UniformRandom(double Min, double Max)
26 this.Min = Min;
27 this.Max = Max;
28 MyUniformRandom = new Random();
31 /// <summary>
32 /// Creates a new uniform random generator with the specified minimum and maximum values and with the specified seed.
33 /// </summary>
34 /// <param name="Min">Represents the minimum value reteurned by this uniform random generator.</param>
35 /// <param name="Max">Represents the maximum value reteurned by this uniform random generator.</param>
36 /// <param name="Seed">Represents the seed used for the internal pseudo-random number generator.</param>
37 public UniformRandom(double Min, double Max, int Seed)
39 this.Min = Min;
40 this.Max = Max;
41 MyUniformRandom = new Random(Seed);
44 /// <summary>
45 /// This function returns the next uniform-randomly generated double number.
46 /// </summary>
47 /// <returns>The next uniform-random double number.</returns>
48 public double NextDouble()
50 return MyUniformRandom.NextDouble() * (Max - Min) + Min;